package o;

import android.app.Activity;
import android.app.PendingIntent;
import com.huawei.hms.api.HuaweiApiAvailability;
import com.huawei.hms.api.HuaweiApiClient;
import com.huawei.hms.support.api.client.ResultCallback;
import com.huawei.hms.support.api.client.Status;
import com.huawei.hms.support.api.pay.GetWalletUiIntentResult;
import com.huawei.hms.support.api.pay.HuaweiPay;
import java.lang.ref.WeakReference;

public class fkn implements ResultCallback<GetWalletUiIntentResult> {
    private HuaweiApiClient ˊ;
    private dmi ˎ = new dmi(this) {
        final /* synthetic */ fkn ˎ;

        {
            this.ˎ = r1;
        }

        public void run() {
            HuaweiPay.HuaweiPayApi.getWalletUiIntent(this.ˎ.ˊ, 0).setResultCallback(this.ˎ);
        }
    };
    private Activity ˏ;

    static class a implements eqr {
        private WeakReference<fkn> ˊ;

        a(fkn o_fkn) {
            this.ˊ = new WeakReference(o_fkn);
        }

        public void ॱ() {
            fkn o_fkn;
            if (this.ˊ == null) {
                o_fkn = null;
            } else {
                o_fkn = (fkn) this.ˊ.get();
            }
            if (o_fkn == null) {
                Logger.ˎ("HuaCoinCenterUtils", "onConnectSucceed interrupt because of payActivity is null.");
            } else if (o_fkn.ˋ()) {
                o_fkn.ˊ();
            } else {
                Logger.ˎ("HuaCoinCenterUtils", "startPayClient interrupt because of checkHmsBranchValid false");
            }
        }

        public void ॱ(int i) {
            Logger.ˋ("HuaCoinCenterUtils", "HwPayClient onConnectFailed，rtnCode:" + i);
        }

        public void ˋ(int i) {
            fkn o_fkn;
            if (Logger.ˎ()) {
                Logger.ˏ("HuaCoinCenterUtils", "HwPayClient onResolveError，support onResolveError:" + i);
            }
            if (this.ˊ == null) {
                o_fkn = null;
            } else {
                o_fkn = (fkn) this.ˊ.get();
            }
            if (o_fkn != null) {
                HuaweiApiAvailability.getInstance().resolveError(o_fkn.ॱ(), i, 1000);
            } else {
                Logger.ˋ("HuaCoinCenterUtils", "HwPayClient onResolveError Interrupted,payActivity is null");
            }
        }
    }

    public /* synthetic */ void onResult(Object obj) {
        ˏ((GetWalletUiIntentResult) obj);
    }

    public fkn(Activity activity) {
        this.ˏ = activity;
    }

    public void ˏ() {
        this.ˊ = eqj.ˋ(new a(this));
        if (ˋ()) {
            ˊ();
        }
    }

    private void ˊ() {
        dmq.ˏ.ॱ(this.ˎ);
    }

    public Activity ॱ() {
        return this.ˏ;
    }

    private boolean ˋ() {
        if (this.ˊ == null) {
            Logger.ˎ("HuaCoinCenterUtils", "startPayClient Failed，Reason：hwpayClient is null");
            return false;
        } else if (this.ˊ.isConnected()) {
            return true;
        } else {
            Logger.ˎ("HuaCoinCenterUtils", "startPayClient Failed，Reason：hwpayClient not connected , wait hwpayClient connected ");
            return false;
        }
    }

    public void ˏ(GetWalletUiIntentResult getWalletUiIntentResult) {
        Status status = getWalletUiIntentResult.getStatus();
        if (status == null) {
            Logger.ˎ("HuaCoinCenterUtils", "startToWalletUi status is null");
            return;
        }
        int statusCode = status.getStatusCode();
        if (statusCode == 0) {
            try {
                PendingIntent pindingIntent = getWalletUiIntentResult.getPindingIntent();
                if (pindingIntent != null) {
                    Logger.ˎ("HuaCoinCenterUtils", "startToWalletUi complete");
                    if (ॱ() != null) {
                        ॱ().startIntentSenderForResult(pindingIntent.getIntentSender(), 0, null, 0, 0, 0);
                        return;
                    } else {
                        Logger.ˎ("HuaCoinCenterUtils", "activity is null");
                        return;
                    }
                }
                Logger.ˎ("HuaCoinCenterUtils", "startToWalletUi PendingIntent is null");
                return;
            } catch (Exception e) {
                Logger.ˎ("HuaCoinCenterUtils", "startToWalletUi PendingIntent Exception");
                return;
            }
        }
        Logger.ˎ("HuaCoinCenterUtils", "startToWalletUi fail error code: " + statusCode);
    }
}
